<?PHP
include("settings.php");
include("connect.php");
include("functions.php");
limits();
include("queries.php");
if (isset($_GET['typeID']) && !empty($_GET['typeID'])) {
$row_all = $db->fetch_assoc($db->query($query12));
$row_month = $db->fetch_assoc($db->query($query13));
$row_week = $db->fetch_assoc($db->query($query14));
}
$result = $db->query($query11);
include("header.php");

echo '<div id="header">
<ul id="tabnav">
	<li><a href="index.php">Home</a></li>
	'.($settings['personaljournal'] == true ? "<li><a href=\"journal.php\">Personal Journal</a></li>" : "").'
	'.($settings['personaltransactions'] == true ? "<li><a href=\"transactions.php\" class=\"active\">Personal Transactions</a></li>" : "").'
	'.($settings['corpjournal'] == true ? "<li><a href=\"corpj.php\">Corporate Journal</a></li>" : "").'
	'.($settings['corptransactions'] == true ? "<li><a href=\"corpt.php\">Corporate Transactions</a></li>" : "").'
	<li><a href="overview.php?wallet=personal'.(isset($_GET['typeID']) && !empty($_GET['typeID']) ? "&typeID=".$_GET['typeID']."" : "").'">Overview</a></li>
	<li id="time">'.get_current_time().'</li>
</ul>
</div>';

echo '
<table id="wrapper" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="6">';

if (isset($_GET['typeID']) && !empty($_GET['typeID'])) {
echo '	
		<table style="text-align:right;" align="left">
		<tr style="text-align:center;">
		<td></td>
		<td>Average</td>
		<td>Minium</td>
		<td>Maximum</td>
		<td>Volume</td>
		</tr>
		<tr>
		<td>All Time</td>
		<td>'.number_format(@($row_all[price]/$row_all[quantity]),'2','.',',').'</td>
		<td>'.number_format($row_all[minimum],'2','.',',').'</td>
		<td>'.number_format($row_all[maximum],'2','.',',').'</td>
		<td>'.number_format($row_all[quantity],'0','.',',').'</td>
		</tr>
		<tr>
		<td>Last Month</td>
		<td>'.number_format(@($row_month[price]/$row_month[quantity]),'2','.',',').'</td>
		<td>'.number_format($row_month[minimum],'2','.',',').'</td>
		<td>'.number_format($row_month[maximum],'2','.',',').'</td>
		<td>'.number_format($row_month[quantity],'0','.',',').'</td>
		</tr>
		<tr>
		<td>Last Week</td>
		<td>'.number_format(@($row_week[price]/$row_week[quantity]),'2','.',',').'</td>
		<td>'.number_format($row_week[minimum],'2','.',',').'</td>
		<td>'.number_format($row_week[maximum],'2','.',',').'</td>
		<td>'.number_format($row_week[quantity],'0','.',',').'</td>
		</tr>
		</table>';
}

echo '
		<table align="right" border="0"><tr>
		<td>
		</td>
		<td>
		<ul id="butnav">
		<li><a href="?">Reset</a></li>
		<li><a href="?settings=save">Save</a></li>
		<li><a href="update.php?wallet=personaltransactions">Update This Wallet</a></li>
		</ul>
		</td>
		<td><form action="" method="get">'.get_input(images).'
Images &nbsp;
			<select name="images" onChange="this.form.submit();">
			<option value="on"'.($settings['images'] == 'on' ? " selected" : "").'>On</option>
			<option value="off"'.($settings['images'] == 'off' ? " selected" : "").'>Off</option>
			</select></form></td>
		<td><form action="" method="get">'.get_input(limit).'
Display &nbsp;
			<select name="limit" onChange="this.form.submit();">
			<option value="'.$limit.'" selected>'.$limit.'</option>
			<option value="40">Forty</option>
			<option value="30">Thirty</option>
			<option value="20">Twenty</option>
			<option value="15">Fifteen</option>
			<option value="10">Ten</option>
			</select></form></td>
		<td valign="bottom"><form action="" method="get">'.get_input(transactionType).'
Transaction Type&nbsp;
			<select name="transactionType" onChange="this.form.submit();">
			<option value=""'.(empty($_GET['transactionType']) OR !isset($_GET['transactionType']) ? " selected" : "").'>Both</option>
			<option value="buy"'.($_GET['transactionType'] == "buy" ? " selected" : "").'>Buy</option>
			<option value="sell"'.($_GET['transactionType'] == "sell" ? " selected" : "").'>Sell</option>
			</select></form></td>
		</tr></table>
		</td>
	</tr>
	<tr><td colspan="6">'.pagination($db->foundRows).'</td></tr>
	<tr>
		<td style="width:80px;">Date Time</td>
		<td>Type Name</td>
		<td>Quantity</td>
		<td>Price</td>
		<td>Client</td>
		<td>Location</td>
	</tr>';
echo '
	<tr>
		<td id="row" style="padding-bottom:5px;">&nbsp;</td>
		<td id="row" style="padding-bottom:5px;">
		'.((isset($_GET['typeID']) OR isset($_GET['typeName'])) ? 
		"".get_restriction(type,personal).""
		 : 
		 "<form action=\"\" method=\"get\">
        <input type=\"text\" name=\"type\" style=\"width:240px;\" />
		<input type=\"hidden\" name=\"typeID\" />
		".get_input(typeName)."<script>
            new CAPXOUS.AutoComplete(\"type\", function() {
                return \"autocomplete.php?type=type&wallet=personal&typing=\" + this.text.value
            });
			clearCurrentLink();
        </script>
		</form>").'
		</td>
		<td id="row" style="padding-bottom:5px;">&nbsp;</td>
		<td id="row" style="padding-bottom:5px;">&nbsp;</td>
		<td id="row" style="padding-bottom:5px;">
		'.((isset($_GET['clientID']) OR isset($_GET['clientName'])) ? 
		"".get_restriction(client,personal).""
		 : 
		 "<form action=\"\" method=\"get\">
        <input type=\"text\" name=\"client\" />
		<input type=\"hidden\" name=\"clientID\" />
		".get_input(clientName)."<script>
            new CAPXOUS.AutoComplete(\"client\", function() {
                return \"autocomplete.php?type=client&wallet=personal&typing=\" + this.text.value
            });
			clearCurrentLink();
        </script>
		</form>").'
		</td>
		<td id="row" style="padding-bottom:5px;">
		'.((isset($_GET['stationID']) OR isset($_GET['stationName'])) ? 
		"".get_restriction(station,personal).""
		 : 
		 "<form action=\"\" method=\"get\">
        <input type=\"text\" name=\"station\" style=\"width:240px;\" />
		<input type=\"hidden\" name=\"stationID\" />
		".get_input(stationName)."<script>
            new CAPXOUS.AutoComplete(\"station\", function() {
                return \"autocomplete.php?type=station&wallet=personal&typing=\" + this.text.value
            });
			clearCurrentLink();
        </script>
		</form>").'
		</td>
	</tr>';

if (mysql_num_rows($result) == 0) {
	echo '<tr><td colspan="6" style="text-align:center;height:75px;border-bottom:1px dashed #000;">
			No transactions found.
		  </td></tr>';
	}
while ($row = $db->fetch_assoc($result)) {
//split datetime
$datetime = explode(" ", $row[transactionDateTime]);

echo '
	<tr onmouseover="setPointer(this, 1, \'over\', \''.$settings['normal'].'\', \''.$settings['rollover'].'\', \''.$settings['click'].'\');" onmouseout="setPointer(this, 1, \'out\', \''.$settings['normal'].'\', \''.$settings['rollover'].'\', \''.$settings['click'].'\');" onmousedown="setPointer(this, 1, \'click\', \''.$settings['normal'].'\', \''.$settings['rollover'].'\', \''.$settings['click'].'\');">
		<td id="row" bgcolor="'.$settings['normal'].'">'.$datetime[0].'<br />'.$datetime[1].'</td>
		<td id="row" bgcolor="'.$settings['normal'].'">
			<a href="?typeID='.$row['typeID'].''.get_query(typeID,typeName).'">
			'.(($settings['images'] == 'on') ? "<img src=\"item.php?i=".intval($row[typeID])."\" alt=\"".$row[typeName]."\" title=\"".$row[typeName]."\" width=\"32\" height=\"32\" border=\"0\" align=\"middle\" />" : "").'
			</a>
			&nbsp;<a href="?typeID='.$row['typeID'].''.get_query(typeID,typeName).'">'.$row[typeName].'</a>
		</td>
		<td id ="row" style="text-align:right;padding-right:10px;" bgcolor="'.$settings['normal'].'">'.$row[quantity].'</td>
		<td id="row" style="text-align:right;padding-right:5px;color: '.($row[transactionType] == 'buy' ? "red" : "green").';" bgcolor="'.$settings['normal'].'">'.number_format($row[price], 2, '.', ',').'</td>
		<td id="row" bgcolor="'.$settings['normal'].'">
			<a href="?clientID='.$row['clientID'].''.get_query(clientID,clientName).'">
			'.(($settings['images'] == 'on') ? "<img src=\"char.php?c=".intval($row[clientID])."\" alt=\"".$row[clientName]."\" title=\"".$row[clientName]."\" width=\"32\" height=\"32\" border=\"0\" align=\"middle\" />" : "").'
			</a>
			&nbsp;<a href="?clientID='.$row['clientID'].''.get_query(clientID,clientName).'">'.$row[clientName].'</a>
		</td>
		<td id="row" bgcolor="'.$settings['normal'].'"><a href="?stationID='.$row['stationID'].''.get_query(stationID,stationName).'">'.$row[stationName].'</td>
	</tr>
';
}// end Row while
echo '
<tr><td colspan="6">'.pagination($db->foundRows).'</td></tr>
</table>
';

include("footer.php");
?>